package com.example.hutool;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.SmUtil;
import cn.hutool.crypto.digest.HMac;
import cn.hutool.crypto.symmetric.SM4;

/**
 * @author 江黎
 * @since 2023-08-03
 */
public class 国密工具类 {

    public static void main(String[] args) {
        // key必须是16位  128 bit => 128 / 8 = 16 byte
        String key = "1234567890123456";
        SM4 sm4 = SmUtil.sm4(key.getBytes());

        String content = "test中文";
        String encryptHex = sm4.encryptHex(content);
        System.out.println("sm4密文:" + encryptHex);
        String decryptStr = sm4.decryptStr(encryptHex, CharsetUtil.CHARSET_UTF_8);
        System.out.println("明文:" + decryptStr);

        // SM3 摘要算法
        HMac sm3 = SmUtil.hmacSm3(key.getBytes());
        String digestHex = sm3.digestHex(content);
        System.out.println("sm3密文:" + digestHex);
    }
}
